﻿using System;
using System.Collections.Generic;
using System.Linq;
using Hopscotch.Common.Contracts.AppService;
using Hopscotch.Domain.Finance;

namespace Hopscotch.Server.AppServiceFake
{
    public class CurrencyInstrumentService : FakeServiceIntKey<CurrencyInstrument>, ICurrencyInstrumentService
    {
        private static bool isInitialized;

        public CurrencyInstrumentService()
        {
            Initialize();
        }

        private void Initialize()
        {
            if (isInitialized)
                return;

            Add(new CurrencyInstrument { Id = 100, Code = "USD", Name = "US Dollar" });
            Add(new CurrencyInstrument { Id = 101, Code = "GBP", Name = "British Pound" });
            Add(new CurrencyInstrument { Id = 102, Code = "EUR", Name = "EUR" });
            Add(new CurrencyInstrument { Id = 103, Code = "HKD", Name = "Hong Kong Dollar" });
            Add(new CurrencyInstrument { Id = 104, Code = "JPY", Name = "Japanese Yen" });


            isInitialized = true;
        }

        public ICollection<CurrencyInstrument> GetAll()
        {
            return FakeData.Values.ToList();
        }

        public CurrencyInstrument Get(string code)
        {
            var q = from ci in FakeData.Values
                    where ci.Code == code
                    select ci;

            return q.FirstOrDefault();
        }
    }
}
